home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 August / EnterCD 08_2005.iso / dosapps / freedos / doc / ctmouse / technote.txt < prev    next >
Encoding:
Text File  |  2002-09-30  |  18.0 KB  |  362 lines

  1. Mouse driver services
  2. ---------------------
  3.  
  4. Functions implemented in CTMOUSE:
  5.  
  6. INT 33/0000 - MS MOUSE - Reset driver and read status
  7. INT 33/0001 - MS MOUSE v1.0+ - Show mouse cursor
  8. INT 33/0002 - MS MOUSE v1.0+ - Hide mouse cursor
  9. INT 33/0003 - MS MOUSE v1.0+ - Get cursor position and buttons status
  10. INT 33/0004 - MS MOUSE v1.0+ - Position mouse cursor
  11. INT 33/0005 - MS MOUSE v1.0+ - Get button press data
  12. INT 33/0006 - MS MOUSE v1.0+ - Get button release data
  13. INT 33/0007 - MS MOUSE v1.0+ - Set horizontal cursor range
  14. INT 33/0008 - MS MOUSE v1.0+ - Set vertical cursor range
  15. INT 33/0009 - MS MOUSE v3.0+ - Define graphics cursor
  16. INT 33/000A - MS MOUSE v3.0+ - Define text cursor
  17. INT 33/000B - MS MOUSE v1.0+ - Get motion counters
  18. INT 33/000C - MS MOUSE v1.0+ - Define User Interrupt Routine
  19. INT 33/000F - MS MOUSE v1.0+ - Set mickeys/pixels ratios
  20. INT 33/0010 - MS MOUSE v1.0+ - Define screen region for updating
  21. INT 33/0014 - MS MOUSE v3.0+ - Exchange User Interrupt Routines
  22. INT 33/0015 - MS MOUSE v6.0+ - Get driver storage requirements
  23. INT 33/0016 - MS MOUSE v6.0+ - Save driver state
  24. INT 33/0017 - MS MOUSE v6.0+ - Restore driver state
  25. INT 33/001A - MS MOUSE v6.0+ - Set mouse sensitivity
  26. INT 33/001B - MS MOUSE v6.0+ - Get mouse sensitivity
  27. INT 33/001E - MS MOUSE v6.0+ - Get display page
  28. INT 33/001F - MS MOUSE v6.0+ - Disable mouse driver
  29. INT 33/0020 - MS MOUSE v6.0+ - Enable mouse driver
  30. INT 33/0021 - MS MOUSE v6.0+ - Software reset
  31. INT 33/0023 - MS MOUSE v6.0+ - Get language for messages
  32. INT 33/0024 - MS MOUSE v6.26+ - Get software version, mouse type and IRQ
  33. INT 33/0026 - MS MOUSE v6.26+ - Get maximum virtual screen coordinates
  34. INT 33/0027 - MS MOUSE v7.01+ - Get screen/cursor masks and mickey counters
  35. INT 33/002A - MS MOUSE v7.02+ - Get cursor hot spot
  36. INT 33/0031 - MS MOUSE v7.05+ - Get current virtual cursor coordinates
  37. INT 33/0032 - MS MOUSE v7.05+ - Get supported advanced functions flag
  38. INT 33/004D - MS MOUSE - Get pointer to copyright string
  39. INT 33/006D - MS MOUSE - Get pointer to version
  40.  
  41. Video functions implemented in CTMOUSE:
  42.  
  43. INT 10/F0 - EGA Register Interface Library - Read one register
  44. INT 10/F1 - EGA Register Interface Library - Write one register
  45. INT 10/F2 - EGA Register Interface Library - Read register range
  46. INT 10/F3 - EGA Register Interface Library - Write register range
  47. INT 10/F4 - EGA Register Interface Library - Read register set
  48. INT 10/F5 - EGA Register Interface Library - Write register set
  49. INT 10/F6 - EGA Register Interface Library - Revert registers to default
  50. INT 10/F7 - EGA Register Interface Library - Define registers default
  51. INT 10/FA - EGA Register Interface Library - Interrogate driver
  52.  
  53. The following functions are not implemented but they don't return
  54. anything and can be counted as implemented:
  55.  
  56. INT 33/000D - MS MOUSE v1.0+ - Light pen emulation ON
  57. INT 33/000E - MS MOUSE v1.0+ - Light pen emulation OFF
  58. INT 33/0013 - MS MOUSE v5.0+ - Define double-speed threshold
  59. INT 33/001C - MS MOUSE v6.0+ - Set interrupt rate
  60. INT 33/001D - MS MOUSE v6.0+ - Set display page
  61. INT 33/0022 - MS MOUSE v6.0+ - Set language for messages
  62.  
  63. The following functions are not implemented:
  64.  
  65. INT 10/04 - VIDEO - Get light pen position (except VGA)
  66. INT 33/0012 - MS MOUSE - Set large graphics cursor block
  67. INT 33/0018 - MS MOUSE v6.0+ - Set alternate User Interrupt Routine
  68. INT 33/0019 - MS MOUSE v6.0+ - Get alternate User Interrupt Routine
  69. INT 33/0025 - MS MOUSE v6.26+ - Get general driver information
  70. INT 33/0028 - MS MOUSE v7.0+ - Set video mode
  71. INT 33/0029 - MS MOUSE v7.0+ - Enumerate video modes
  72. INT 33/002B - MS MOUSE v7.0+ - Load acceleration profiles
  73. INT 33/002C - MS MOUSE v7.0+ - Get acceleration profiles
  74. INT 33/002D - MS MOUSE v7.0+ - Select acceleration profile
  75. INT 33/002E - MS MOUSE v8.10+ - Set acceleration profile names
  76. INT 33/002F - MS MOUSE v7.02+ - Mouse hardware reset
  77. INT 33/0030 - MS MOUSE v7.04+ - Get/Set BallPoint information
  78. INT 33/0033 - MS MOUSE v7.05+ - Get switch settings and acceleration profile data
  79. INT 33/0034 - MS MOUSE v8.0+ - Get initialization file
  80. INT 33/0035 - MS MOUSE v8.10+ - LCD screen large pointer support
  81.  
  82.  
  83. Details of driver operation
  84. ---------------------------
  85.  
  86. CTMOUSE displays the cursor only in standard video modes of CGA, EGA and
  87.   VGA; Hercules Graphics/InColor Card or SVGA/VESA extended video modes
  88.   are not supported but an application can display the cursor by itself in
  89.   a user interrupt routine (may be installed by INT 33/000C function) or
  90.   when idle. Remember to remove calls to INT 33/0001 (Show cursor) and
  91.   define cursor movement limits (INT 33/0007 and INT 33/0008).
  92.  
  93. Some applications call INT 33/0001 (Show cursor), INT 33/0009 (Define
  94.   graphics cursor) and INT 33/000A (Define text cursor) in loops. To
  95.   prevent cursor flickering INT 33/0001 function redraws cursor only if it
  96.   was hidden before and INT 33/0004 (Position cursor), INT 33/0009 and
  97.   INT 33/000A functions redraw cursor only if its position or pattern
  98.   has changed.
  99.  
  100. Unlike many other mouse drivers, CTMOUSE doesn't require call INT 33/0002
  101.   (Hide cursor) or INT 33/0010 (Define region for updating) before writing
  102.   to the screen in text mode because screen under cursor isn't restored if
  103.   cursor is overwritten. However CTMOUSE can't correct all cases of cursor
  104.   overwriting: when a character is written at the cursor position without
  105.   an attribute, (through INT 10/0E (Teletype output) or INT 21), then it
  106.   gets the cursor's attribute. Also, if cursor is overwritten by character
  107.   with attribute which is equal to cursor's character/attribute then
  108.   CTMOUSE restores the old character/attribute.
  109.  
  110. Unlike Microsoft's specification, CTMOUSE always displays cursor on the
  111.   active video page and doesn't require call INT 33/001D (Set display
  112.   page) at all; this function is, anyway, a dummy.
  113.  
  114. Below is a table of virtual screen size, cursor movement granularity and
  115.   minimum/maximum size of region on the screen, occupied by cursor (actual
  116.   for INT 33/0010) for each video mode:
  117.                  min     max
  118.     mode     screen  cell    shape    shape
  119.      *0    640x200  16x8    16x8    16x8
  120.      *1    640x200  16x8    16x8    16x8
  121.      *2    640x200   8x8     8x8     8x8
  122.      *3    640x200   8x8     8x8     8x8
  123.       4    640x200   2x1    16x16    24x16
  124.       5    640x200   2x1    16x16    24x16
  125.       6    640x200   1x1    16x16    24x16
  126.      *7    640x200   8x8     8x8     8x8
  127.      0Dh    640x200   2x1    32x16    48x16
  128.      0Eh    640x200   1x1    16x16    24x16
  129.      0Fh    640x350   1x1    16x16    24x16
  130.      10h    640x350   1x1    16x16    24x16
  131.      11h    640x480   1x1    16x16    24x16
  132.      12h    640x480   1x1    16x16    24x16
  133.      13h    640x200   2x1    32x16    32x16
  134.     other    640x200   1x1      -      -
  135.  
  136.   * for text modes, the virtual screen size is given for standard screen
  137.   sizes 40x25 and 80x25; for other screen sizes the corresponding virtual
  138.   screen size is changed accordingly.
  139.  
  140. In standard text modes, CTMOUSE supports any screen size beside 40x25 and
  141.   80x25. It sets virtual screen size as [screen width in characters]*8 by
  142.   [screen height in characters]*8 (except video modes 0-1, where width is
  143.   multiplied by 16) each time when the video mode or the screen size is
  144.   changed or INT 33/0000 (Reset driver), INT 33/0020 (Enable driver) or
  145.   INT 33/0021 (Software reset) are called.
  146.  
  147. CTMOUSE intercepts only INT 10/0 (Set video mode), INT 10/111x (Load and
  148.   activate font) and INT 10/4F02 (Set VESA/SVGA video mode) functions. If
  149.   screen size in text mode changed by other functions like INT 10/1Ch (VGA
  150.   state save/restore) or by direct hardware programming, then INT 33/0000
  151.   (Reset driver), INT 33/0020 (Enable driver) or INT 33/0021 (Software
  152.   reset) must be called to renew virtual screen size. If INT 33/0020 only
  153.   is called then INT 33/0007 (Set horizontal range) and INT 33/0008 (Set
  154.   vertical range) also should be called with min=0 and max=[8*screen
  155.   width-1,8*screen height-1] to enable the complete screen for cursor
  156.   movement.
  157.  
  158. INT 33/0007 (Set horizontal range) and INT 33/0008 (Set vertical range)
  159.   functions setup cursor movement area but cursor will be seen on the
  160.   screen only in standard video modes and when cursor shape intersects
  161.   with virtual screen coordinates.
  162.  
  163. All driver's coordinates (ranges, cursor positions, regions) interpreted
  164.   as signed values, also as cursor hot spot or mickey counts.
  165.  
  166.  
  167. Notes for mouse driver services
  168. -------------------------------
  169.  
  170. For bitmapped graphics modes 4-6 and 0Dh-12h a peculiarity of INT 33/0010
  171.   (Define region for updating) function should be noted: horizontal cursor
  172.   position is always aligned by modulo 8 or 16 and cursor occupies 24 or
  173.   48 positions, unlike mode 13h, where start position is unchanged and
  174.   cursor occupies 32 positions; i.e. for left limit L and right limit R in
  175.   modes 4-6, 0Eh-12h cursor will be hidden between (L-L%8)-16 and
  176.   [R/8+1]*8-1 positions, in mode 0Dh cursor will be hidden between
  177.   (L-L%16)-32 and [R/16+1]*16-1 positions and in mode 13h cursor will be
  178.   hidden between L-32 and R positions.
  179.  
  180. To set update region via INT 33/0010 in terms of character positions you
  181.   must compute arguments as CX=left*W, DX=top*8, SI=(right+1)*W-1 and
  182.   DI=(bottom+1)*W-1, where W=16 for modes 0-1, 4-5, 0Dh and 13h and W=8
  183.   for all other modes.
  184.  
  185. Size of buffer, required to save driver state by INT 33/0016, in CTMOUSE
  186.   is less than 180 bytes; exact buffer size is returned by INT 33/0015
  187.   (Get driver storage requirements).
  188.  
  189. INT 33/0016 (Save driver state) and INT 33/0017 (Restore driver state)
  190.   functions save and restore user defined variables (mickeys per 8 pixels,
  191.   user interrupt routine call mask and address), cursor definition (cursor
  192.   type, text and graphics shape, visibility, position, ranges and update
  193.   region) and mouse access state (mickeys mouse moved, buttons press and
  194.   release status since last access). These functions don't affect driver
  195.   state (disabled flag, resolution level), mouse definition (mouse type,
  196.   buttons count, IO address and interrupt), video mode definition (maximum
  197.   virtual screen coordinates, EGA RIL register values) and dummy variables
  198.   (lightpen emulation status and double speed threshold).
  199.  
  200. When the video mode after INT 10/0 or INT 10/4F02 or screen size after
  201.   INT 10/111x is changed, CTMOUSE hides cursor so that it can be shown by
  202.   next INT 33/0001, recalculates screen sizes, sets cursor ranges to
  203.   virtual screen sizes and centers cursor.
  204.  
  205. INT 33/0000 (Reset driver) and INT 33/0021 (Software reset) functions hide
  206.   cursor (so that it can be shown by next INT 33/0001), recalculate screen
  207.   sizes, set cursor ranges to screen sizes, center cursor and clear mickey
  208.   counts, user interrupt routine call mask and button press/release data.
  209.   In addition, horizontal mickeys per 8 pixels ratio is set to 8, vertical
  210.   mickeys per 8 pixels ratio is set to 16, software text mode cursor is
  211.   set with reverse video shape (screen mask 77FFh, cursor mask 7700h) and
  212.   graphics mode cursor shape is set to arrow with zero hot spot.
  213.  
  214. INT 33/001F (Disable driver) function hides cursor so that it can be shown
  215.   by next INT 33/0001, disables mouse, restores IRQ interrupt (for serial
  216.   mouse) and returns in ES:BX the old INT 33 interrupt handler address. If
  217.   INT 33 or INT 10 interrupt was intercepted by another program then on
  218.   exit AX will contain -1, else if INT 10 interrupt handler was not
  219.   restored yet then it will be restored.
  220.  
  221. INT 33/0020 (Enable driver) function installs IRQ handler (if serial mouse
  222.   is active) and INT 10 handler (if it is not yet installed), enables
  223.   mouse interrupts, recalculates screen sizes, sets cursor ranges to
  224.   screen sizes and centers cursor.
  225.  
  226. CTMOUSE supports INT 33/0022 and 0023 (Set/get language for messages)
  227.   functions, but only for English.
  228.  
  229. When you have to deal with RIL, keep in mind that RIL is unprotected from
  230.   wrong user input - RIL functions should be called only in standard video
  231.   modes and on EGA or later video adapters, and RIL doesn't check if group
  232.   index, register number or count of registers are valid.
  233.  
  234.  
  235. Asynchronous execution and User Interrupt Routine (UIR)
  236. ------------------------------------------------------
  237.  
  238. UIR installed via INT 33/000C (Define UIR) or INT 33/0014 (Exchange UIRs)
  239.   must use far RET (not IRET) for return and it is not required to keep
  240.   any register value except SS:SP.
  241.  
  242. Mouse interrupt handler (IH) redraws cursor on the screen only when the
  243.   called UIR returns to IH. If new mouse events occur before UIR returns
  244.   to IH, then IH will not redraw cursor and call UIR again (i.e. UIR is
  245.   not required to be re-enterable). However, mouse events themselves
  246.   will be parsed and reflected in driver state, so driver state (cursor
  247.   position, buttons state) may be changed before UIR returns. Therefore,
  248.   UIR should be aware of a possible difference between initial arguments
  249.   and values returned by driver functions.
  250.  
  251. Driver functions will not hide or redraw cursor if they are called while
  252.   cursor hidding or drawing routines in the driver are already working.
  253.   This means that cursor will not be redrawn by requests from UIR or any
  254.   other general purpose hardware interrupt handler, if they are executed
  255.   while cursor redrawing was in progress (this will look like cursor on
  256.   the screen freezes). But hidding or drawing routines will be called
  257.   again when they finish their first request if new request comes in
  258.   from interrupt handlers while they are working.
  259.  
  260. When bit 0 ("call if mouse moves") is set in the UIR call mask then UIR
  261.   will be called when any mickey count is changed. Note: cursor position
  262.   usually changes less often than mickey counts because mickeys per 8
  263.   pixels ratios can reduce mickeys change to zero and cursor position
  264.   change can be hidden by granulation (in text modes cursor positions are
  265.   always factor of 8 or 16; in some graphics modes X cursor positions are
  266.   always factor of two).
  267.  
  268.  
  269. Used BIOS variables
  270. -------------------
  271.  
  272. 0:449h    bits 0-6 used to determine the current video mode (when driver
  273.     enabled by INT 33/0020 or video mode changed)
  274. 0:44Ah    screen width in text columns (used to compute offset in video
  275.     memory in text video modes)
  276. 0:44Eh    offset in video segment of active video memory page
  277. 0:462h    current video page (returned by INT 33/001E)
  278. 0:463h    used to compute CRTC base and Feature Control video ports addresses
  279.     (when driver enabled by INT 33/0020 or video mode changed)
  280. 0:46Ch    timer used in mouse detection routine to make timing
  281. 0:487h    bits 5-6 used to determine RAM size on video adapter (when driver
  282.     enabled by INT 33/0020 or video mode changed)
  283. 0:488h    bits 0-3 used to get video configuration switches (when driver
  284.     enabled by INT 33/0020 or video mode changed)
  285. 0:4A8h    used to get default video registers values for RIL (when driver
  286.     enabled by INT 33/0020 or video mode changed)
  287.  
  288.  
  289. Used interrupts
  290. ---------------
  291.  
  292. INT 10/01    setup text-mode hardware cursor shape, when hardware
  293.         cursor selected
  294. INT 10/1A00    get DCC to check VGA presence
  295. INT 15/C200    enable/disable PS/2 pointing device
  296. INT 15/C203    set resolution of PS/2 pointing device [when PS/2 checking]
  297. INT 15/C205    initialize PS/2 pointing device [when PS/2 checking]
  298. INT 15/C207    set handler for PS/2 pointing device
  299. INT 21/09    output all strings to standard output
  300. INT 21/25    install interrupt handlers for INT 33, INT 10 and IRQ
  301.         handler, also restore those interrupts
  302. INT 21/26    create new PSP for driver image in the UMB [when trying    to
  303.         install driver high]
  304. INT 21/31    remain TSR when driver not copied to other UMB segment
  305. INT 21/35    save old INT 33, INT 10 and IRQ handlers addresses
  306. INT 21/48    allocate UMB memory [when trying to install driver high]
  307. INT 21/49    free memory used by environment and by unloaded TSR
  308. INT 21/4C    terminate program with nonzero errorlevel if some error
  309.         found or with zero errorlevel when no errors
  310. INT 21/58    modify memory allocation strategy [when trying to install
  311.         driver high]
  312. INT 2F/4310    get XMS driver entry [when trying to install driver high]
  313. INT 33/001F    disable previous mouse driver, if one is present
  314. INT 33/0020    enable previous mouse driver after unloading CuteMouse
  315. INT 33/004D    check if installed driver is CuteMouse
  316.  
  317.  
  318. Techniques used
  319. ---------------
  320.  
  321. 1. Two writes to adjacent I/O ports are combined into one write "out dx,ax"
  322.    (used for most video registers, divisor latch of COM port, etc).
  323.  
  324. 2. For interrupt handler's address comparision only segment of address is
  325.    used, because usually different programs reside in different segments
  326.    and no one program is pointed to by zero segment.
  327.  
  328. 3. CuteMouse uses a lot of self-modifying code and many variables are
  329.    placed in the code instructions; most of code modification is grouped
  330.    in the setupdriver and softreset_21 procedures.
  331.  
  332. 4. To use free part of PSP and thus minimize memory footprint, CuteMouse
  333.    source includes corresponding "ORG" statement before uninitialized
  334.    variables, for which only offsets are computed and no data is generated.
  335.    Note: in TASM 3.1, a structure instance with "DUP(?)" generates data
  336.    (fixed in TASM 4.1), so buttpress and buttrelease arrays are defined
  337.    without "DUP" as series of BUTTLASTSTATE structure insertions instead.
  338.  
  339. 5. CuteMouse is written using TASM and makes use some of TASM features:
  340.    for example, multiple "push" and "pop" in one line ("push ax bx") and
  341.    shifts with an immediate value >1 ("shl ax,2"), which are converted
  342.    into several opcodes valid for 8086/8088 CPUs (i.e. for shifts, TASM
  343.    simply duplicates them - "shl ax,1/shl ax,1"), because there is no
  344.    ".186" or higher statement.
  345.  
  346. 6. Often instructions with shorter opcode but slightly different behavior
  347.    than assumed instruction are used to minimize code; each such use is
  348.    marked by "OPTIMIZE" comment. In addition, instructions for which
  349.    functions are performed by previous code remain in the source as
  350.    comments; this is done for greater readability and to ease code
  351.    carrying.
  352.  
  353. 7. To ease code pipelining in CPU, instructions which manipulate common
  354.    registers or other resources are interspersed with other kinds of
  355.    instructions whenever possible. For example:
  356.  
  357.     mov ax,cx        mov ax,cx
  358.     add ax,bx        neg dx
  359.     neg dx            add ax,bx
  360.  
  361.    here second variant is preferred.
  362.